package cn.edu.jmu.oelp.utils;

import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.*;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class AnsjUtils {
    private String text = null;
    private final List<String> list = new ArrayList<>();

    public AnsjUtils() {
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public List<String> getList() {
        return list;
    }

    public void toAnalysis(){
        list.clear();
        Result result = ToAnalysis.parse(text);
        List<Term> terms = result.getTerms();
        for (Term t : terms) {
            String word = t.getName();
            list.add(word);
        }
    }

    public void dicAnalysis(){
        list.clear();
        Result result = DicAnalysis.parse(text);
        List<Term> terms = result.getTerms();
        for (Term t : terms) {
            String word = t.getName();
            list.add(word);
        }
    }
    public void nlpAnalysis(){
        list.clear();
        Result result = NlpAnalysis.parse(text);
        List<Term> terms = result.getTerms();
        for (Term t : terms) {
            String word = t.getName();
            list.add(word);
        }
    }
    public void indexAnalysis(){
        list.clear();
        Result result = IndexAnalysis.parse(text);
        List<Term> terms = result.getTerms();
        for (Term t : terms) {
            String word = t.getName();
            list.add(word);
        }
    }
    public void baseAnalysis(){
        list.clear();
        Result result = BaseAnalysis.parse(text);
        List<Term> terms = result.getTerms();
        for (Term t : terms) {
            String word = t.getName();
            list.add(word);
        }
    }
}
